package org.xiaom.butler.controller.app;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.xiaom.butler.bean.Hotel;
import org.xiaom.butler.service.BaseService;
import org.xiaom.butler.util.Util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class DataGetter extends HttpServlet {
	BaseService hotelService = new BaseService(Hotel.class);

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse resp)
			throws ServletException, IOException {
		String id=Util.getQueryParam(request, "hotel", "1");
		Hotel h=(Hotel) hotelService.get(id);
		Gson gson=new GsonBuilder().setVersion(1).create();
		System.out.println(gson.toJson(h));
		resp.getWriter().write(gson.toJson(h));
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
